Skip to content

feat: sharpen touch feel across the mobile swipe feed - #227

Merged
therealsama merged 1 commit into
mainfrom
feat/mobile-touch-feel
Sep 2, 2026
Merged

therealsama merged 1 commit into
mainfrom
feat/mobile-touch-feel

Conversation

@therealsama

@therealsama therealsama commented Aug 15, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Five defects that each broke the illusion of a native feed on a phone. The first four are gesture and feedback gaps in mobile swipe mode; the fifth is a layout token that was wrong at every breakpoint, desktop included.

  • Pull-to-refresh no longer costs you your place in the feed. Swipe mode scrolls the document itself, so browsers chained an overscroll at its top edge into a reload that dropped the reader back at the first story. overscroll-behavior-y: contain blocks the chain while keeping the rubber-band none would also remove. It sits on bare html rather than scoped to swipe-mode, because /#/user/:id strips that class and is just as expensive to reload.
  • Taps now produce feedback. Tailwind compiles hover: inside @media (hover: hover) and its preflight zeroes -webkit-tap-highlight-color, so on a coarse pointer a tap gave no visual response at all. Every hover affordance that changes appearance has a matching active: state now, and enableTouchActiveStates() registers a passive document touchstart because iOS fires :active only where such a listener exists. One exclusion is deliberate: the active header tab, whose hover equals its base state.
  • A committed swipe decelerates instead of stopping dead. The settle animation ran on linear, arriving at full speed and halting. It rides cubic-bezier(0.2, 0.3, 0.45, 1) now, leaving the origin at the finger's release speed — measured over the last 80ms of the drag rather than averaged across the whole gesture — and its duration budget scales by the curve's initial slope, derived from the control points instead of restated beside them.
  • The long-press selection UI no longer swallows the swipe. Once the platform's selection handles were up, the browser owned the drag. Selection is suppressed on chrome and panels, and any live selection is collapsed when the gesture locks horizontal. Every touch listener in useSwipeScroll is { passive: true }, so preventDefault() is unavailable and these two are the only levers.
  • The header no longer paints over the story it sits above. --header-height was the literal 53px, and fixed panels plus the scroll indicator reserve space with it. That literal described the real header only at a 16px root font on a phone: at a 150% font setting the header renders 79px, so the token under-reserved by 26px and left the title's first line beneath it, while over-reserving by 8px on desktop. It is calc(3.25rem + 1px) now — a 2.25rem control row, the vertical padding, and the 1px border — measured exact across 12 combinations of viewport and root font size.

Worth a closer look

  • The selection lock is scoped to (any-pointer: coarse). The gesture is touch-only, so a mouse has no swipe to protect and keeps ordinary selection. any- rather than pointer: or hover: deliberately: Gecko has reported the primary pointer as fine on touch-only Android phones (mozilla bug 1556983), which is the browser this was reported from, and any- covers a touch laptop besides.
  • Prose stays selectable; the headline does not. .comment-content opts back in, since copying a quote is native behaviour worth keeping. A text post's title has no link wrapping it, so a long press there raises the handles rather than the link callout — the exact failure the rest of this PR removes. Content links keep their -webkit-touch-callout, which on iOS is currently the only way to lift a URL out of the feed.
  • Breakpoint overrides go through Tailwind's @variant, not a hand-written min-width. rem inside a media query resolves against the browser's initial font size, so a px query would have flipped the token 384px early for a reader at 150% and reintroduced the drift at the boundary. The same mismatch is fixed in .page-state-center-padded. The one px query left is deliberate and now says so: body's offline-bar padding gates on which layout React mounted, and useIsMobile decides that with (max-width: 767px).
  • Each new assertion was verified to fail against the mistake it exists to catch, not merely to pass. That includes a source-level guard that every hover: utility has an active: twin with the same variants and property, because a synthesised press leaves :active unset in every engine CI can drive.

Trade-offs and open questions

  • An installed PWA has no address bar, so pull-to-refresh was the reader's only reload affordance and nothing in the app replaces it.
  • ThemeToggle's dark hover is lighter than on main. Its opaque dark:hover:bg-muted was dropped in favour of the ghost variant's /50, which is what the new press state matches.
  • A touch laptop keeps the selection lock, so a mouse on that device can't select a headline either.
  • Two hand-written :hover rules in index.css sit outside the guard above and outside any (hover: hover) query, so a finger does reach them — as sticky hover rather than as a press.
  • Press-in timing is uneven: pills carry transition-colors and fade over 150ms where the story row snaps. And whether the settle handoff reads as continuous needs an actual thumb; the 80ms window and the 1.2× boost are the numbers to try against if it feels off.

Test plan

  • npm run typecheck, npm run lint, npm run build
  • npm run test:run — 973 unit tests pass
  • npm run e2e — 716 pass, 0 flaky, across Chromium, Firefox, Mobile Safari, and Mobile Chrome
  • New guards stressed with --repeat-each=3 --retries=0 after fixing a mid-reflow race in one assertion

@therealsama
therealsama requested a review from kplachkov as a code owner August 15, 2026 21:14
@therealsama
therealsama force-pushed the feat/mobile-touch-feel branch from b56e8e1 to ababd55 Compare August 28, 2026 18:18
@therealsama
therealsama force-pushed the feat/mobile-touch-feel branch 6 times, most recently from a160b4a to b04e134 Compare August 29, 2026 18:11
@therealsama
therealsama force-pushed the feat/mobile-touch-feel branch 3 times, most recently from 7026195 to f37041f Compare September 2, 2026 04:22
Five defects that each broke the illusion of a native feed on a phone. The
first four are gesture and feedback gaps on a touch pointer; the fifth is a
layout token that was wrong at every breakpoint, desktop included.

- Contain vertical overscroll. Swipe mode scrolls the document itself, so the
  document scroller is the feed, and mobile browsers chained an overscroll at
  its top edge into pull-to-refresh — reloading the SPA and dropping the reader
  back at the first story. `contain` blocks the chain while keeping the local
  rubber-band that `none` would also remove. It sits on bare `html` rather than
  on swipe mode: testing on a phone found the profile route, which strips that
  class deliberately, reloading just as expensively. The cost is worth naming:
  an installed PWA has no address bar, so this gesture was the reader's only
  reload affordance and nothing replaces it.

- Pair every hover affordance with a press state. Tailwind scopes `hover:`
  behind a `(hover: hover)` media query and its preflight zeroes the tap
  highlight, so a tap on a coarse pointer got no feedback at all. Reaching iOS
  took one more step: Safari applies `:active` only where a touch handler sits
  on the element or the document, and this app's only touchstart is on the swipe
  container — so the header, which mounts above the router, and every non-swipe
  route had no press feedback and no highlight left to fall back on. A passive
  no-op on the document is the whole fix. Dropdown items reach the same dead end
  from the other side: Radix guards its highlight behind `pointerType ===
  'mouse'`, so neither `hover:` nor `focus:` survives a touch press on the one
  menu that exists only where the nav is too narrow to hold its tabs.

- Settle a committed swipe on a decelerating curve instead of `linear`, which
  arrived at full speed and stopped dead. Duration is budgeted against the
  curve's initial speed, so its first frame matches the finger rather than
  overshooting it, and the speed it inherits is measured over the last 80ms of
  the drag instead of averaged across the whole gesture. That average lost to
  the velocity floor on nearly every swipe, which left two gestures covering the
  same distance settling identically however they ended. A finger held still
  before lifting now reports a standstill rather than replaying its last burst
  of movement.

- Guard the long-press selection UI, whose handles swallowed the drag:
  suppressed on chrome and collapsed at gesture lock, while story and comment
  prose stay selectable. Headlines are not, which testing on a phone settled: an
  Ask or Show post carries no URL, so its title renders as bare text and a long
  press raised the handles rather than a link callout. Content links do keep
  their callout, since those are arbitrary third-party URLs mid-thread and
  nothing else reaches them.

- Derive `--header-height` from the header. Fixed swipe panels and the scroll
  indicator reserve space with this token, so when it under-reports the header
  paints over the top of every story — and the literal `53px` only ever
  described the header at a 16px default font size on a phone. At a 150%
  setting the header renders 79px. It is now `calc(3.25rem + 1px)`: the 2.25rem
  control row, the vertical padding, and the bottom border. The md/lg values
  come from Tailwind's variant directive rather than a hand-written px query,
  because the utilities they mirror compile to rem breakpoints that move with
  the reader's font size. Desktop had also been over-reserving by 8px, since
  only the base padding was ever encoded.

Two sibling cleanups ride along. `.page-state-center-padded` is hand-written
CSS standing in for a `max-w-6xl` utility container, and its gutters carried
the same px-versus-rem mismatch. The theme toggle drops a `dark:hover:bg-muted`
that was beating the ghost variant's `dark:hover:bg-muted/50` outright, since
`cn()` is tailwind-merge and the button's own class lands last — leaving its
dark hover opaque against a dark press at half that. Deleting it settles both
on the variant's value. The body rule reserving room for the offline bar keeps
its px query on purpose and now says why: it gates on which layout React
mounted, which `useIsMobile` decides with `(max-width: 767px)`.

Two new e2e specs hold all of it in place. `layout-tokens` measures both chrome
tokens against the elements they describe, across four breakpoints at two font
sizes and under emulated browser font settings. `touch-feel` pins the overscroll
containment, including on the route that drops swipe mode, the selection
collapse, and the iOS touch listener — each invisible in CI and only
reproducible on hardware. The release-velocity estimator is unit tested
directly, alongside a pair of gestures with identical displacement and different
endings that fails against the old averaging. One existing spec stops asserting
a literal 53px and 32px for padding these tokens already describe, and measures
the chrome instead. Press states are the one surface no rendered test reaches,
since a synthesised press leaves `:active` unset in every engine CI can drive, so
a source-level check pairs each hover affordance with its `active:` twin. Every
assertion was verified to fail against the mistake it exists to catch, not just
to pass.
@therealsama
therealsama merged commit a1d565e into main Sep 2, 2026
4 checks passed
@therealsama
therealsama deleted the feat/mobile-touch-feel branch September 2, 2026 07:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants